﻿using SmartSapce.ServiceLocation;
using SmartSpace.Core;
using SmartSpace.Web;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace SmartSpace.WebApp._console.dashboard
{
    public partial class index : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            ICoreService service = ServiceLocator.Get<ICoreService>();

            if (SsSite.Current == null)
            {
                _ctlPanelNoApp.Visible = true;
                _ctlPanelAppInfo.Visible = false;

                _ctlEditHostUrl.Text = SsSite.HostUrl;
                _ctlEditName.Text = "SmartSpace Web Application";


                _ctlLinkAdministrator.Text = service.GetUser(SsSite.Current.SuperAdminUserId.Value).Name;
                _ctlLinkAnonymous.Text = "none";
            }
            else
            {
                _ctlPanelNoApp.Visible = false;
                _ctlPanelAppInfo.Visible = true;

                _ctlLinkHostUrl.Text = SsSite.Current.HostUrl;
                _ctlLabelName.Text = SsSite.Current.Title;


                _ctlLinkAdministrator.Text = service.GetUser(SsSite.Current.SuperAdminUserId.Value).Name;
                if (SsSite.Current.IsAllowAnonymous)
                {
                    _ctlLinkAnonymous.Text = service.GetUser(SsSite.Current.AnonymousUserId.Value).Name;
                }

                if (SsSite.Current.DefaultPageId != null)
                {
                    _ctlLinkDefaultPage.Text = service.GetPage(SsSite.Current.Id, SsSite.Current.DefaultPageId.Value).Caption;
                }
            }
        }

        protected void _ctlBtnReload_Click(object sender, EventArgs e)
        {
            SsSite.ReLoad();
            Response.Redirect(Request.Url.OriginalString);
        }
    }
}